﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Greve
{
	public partial class AddJump : Form
	{
		List<JumpCode> _code;
		int _height;

		public List<Dive> dd;
        private Dive d;
		public bool b;
		public AddJump(List<JumpCode> code, int max)
		{
			_height = max;
			_code = code;
			InitializeComponent();

            dd = new List<Dive>();

			d = new Dive();
			foreach(JumpCode c in _code)
			{
				if (_height == 1)
					if (c.oneMeter != 0.0)
						listBoxJump.Items.Add((c.code + " " +c.name));
				if (_height == 3)
					if (c.threeMeter != 0.0)
						listBoxJump.Items.Add((c.code + " " +c.name));
				if (_height == 5)
					if (c.fiveMeter != 0.0 || c.sevenMeter != 0.0 || c.tenMeter != 0.0)
					{
                        if(c.fiveMeter != 0.0)
						    listBoxJump.Items.Add((c.code + " 5M" + " " + c.name));
                        if (c.sevenMeter != 0.0)
                            listBoxJump.Items.Add((c.code + " 7M" + " " + c.name));
                        if (c.tenMeter != 0.0)
                            listBoxJump.Items.Add((c.code + " 10M" + " " + c.name));
					}
			}

			listBoxJump.Focus();
		}

		private void buttonAdd_Click(object sender, EventArgs e)
		{
            foreach(String s in listBoxJump.SelectedItems)
            {
                int i = 0;
                d = new Dive();
			    d.jump = "";
			    d.ID = s.Split(' ')[0];
			    foreach (String str in s.Split(' '))
			    {
				    if (i != 0 || _height == 5 && i != 1)
					    d.jump += str;
				    i++;
			    }

			    String []dif = s.Split(' ');
                foreach (JumpCode c in _code)
                {
                    if (c.code.Equals(dif[0]))
                    {
                        if (_height == 1)
                        {
                            d.difficulty = c.oneMeter;
                            d.height = (int)c.oneMeter;
                        }
                        if (_height == 3)
                        {
                            d.difficulty = c.threeMeter;
                            d.height = (int)c.threeMeter;
                        }
                        if (_height == 5 && dif[1].Equals(c.fiveMeter))
                        {
                            d.difficulty = c.fiveMeter;
                            d.height = (int)c.fiveMeter;
                        }
                        if (_height == 5 && dif[1].Equals(c.sevenMeter))
                        {
                            d.difficulty = c.sevenMeter;
                            d.height = (int)c.sevenMeter ;

                        }
                        if (_height == 5 && dif[1].Equals(c.tenMeter))
                        {
                            d.difficulty = c.tenMeter;
                            d.height = (int)c.tenMeter;

                        }
                    }
                }
                dd.Add(d);
            }
			
			b = true;
			this.Close();
		}

		private void buttonCancel_Click(object sender, EventArgs e)
		{
			b = false;
			this.Close();
		}
	}
}
